package com.glsc.ngateway.common.xir.repo;

import com.glsc.ngateway.common.xir.domain.TtrdSetInstruction;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TtrdSetInstructionRepository extends JpaRepository<TtrdSetInstruction, String>, JpaSpecificationExecutor<TtrdSetInstruction> {

    @Query(value = "select * from XIR_TRD.TTRD_SET_INSTRUCTION where 1=1 " +
            "and (:biztype is null or BIZTYPE = :biztype) " +
            "and (:date is null or SETDATE = :date) " +
            "and (coalesce(:cashAccidList, null) is null or CASH_ACCID  in (:cashAccidList)) " +
            "and (coalesce(:secuAccidList, null) is null or SECU_ACCID  in (:secuAccidList)) " +
            "", nativeQuery = true)
    List<TtrdSetInstruction> findAllByBiztypeAndSetdateAndCashAccidInAndSecuAccidIn(@Param("biztype") String biztype,
                                                                                    @Param("date") String date,
                                                                                    @Param("cashAccidList") List<String> cashAccidList,
                                                                                    @Param("secuAccidList") List<String> secuAccidList);

    List<TtrdSetInstruction> findAllByIntordidIn(List<String> intordIdList);
}